package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.provinceindex.LindiProvinceIndexQueryVO;
import com.minimalist.common.entity.lindi.vo.provinceindex.LindiProvinceIndexVO;
import com.minimalist.common.feign.client.lindi.LindiProvinceIndexFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 林地指标交易平台_省级指标控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_省级指标管理")
@RequestMapping("/basic/lindi/provinceIndex")
public class LindiProvinceIndexController{

    @Autowired
    private LindiProvinceIndexFeignClient feignClient;

    @PostMapping("/addProvinceIndex")
    @Operation(summary = "添加省级指标")
    @SaCheckPermission("lindi:provinceIndex:add")
    public R<?> addProvinceIndex(@RequestBody @Validated(Add.class) LindiProvinceIndexVO indexVO){
        indexVO.setCreateId(StpUtil.getLoginIdAsLong());
        indexVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        indexVO.setCreateTime(now);
        indexVO.setUpdateTime(now);
        return feignClient.addProvinceIndex(indexVO);
    }

    @DeleteMapping("/deleteProvinceIndexByProvinceIndexId")
    @Operation(summary = "删除省级指标 -> 根据省级指标ID删除")
    @SaCheckPermission("lindi:provinceIndex:delete")
    public R<?> deleteProvinceIndexByProvinceIndexId(
            @RequestParam("provinceIndexId")
            @NotNull(message = "省级指标ID不能为空")
            @Parameter(name = "provinceIndexId", required = true, description = "省级指标ID")
            Long provinceIndexId){
        return feignClient.deleteProvinceIndexByProvinceIndexId(provinceIndexId);
    }

    @PutMapping("/updateProvinceIndexByProvinceIndexId")
    @Operation(summary = "修改省级指标")
    @SaCheckPermission("lindi:provinceIndex:update")
    public R<?> updateProvinceIndexByProvinceIndexId(
            @RequestBody @Validated(Update.class) LindiProvinceIndexVO indexVO){
        indexVO.setCreateId(StpUtil.getLoginIdAsLong());
        indexVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        indexVO.setCreateTime(now);
        indexVO.setUpdateTime(now);
        return feignClient.updateProvinceIndexByProvinceIndexId(indexVO);
    }

    @GetMapping("/getPageProvinceIndexList")
    @Operation(summary = "查询省级指标列表(分页)")
    @SaCheckPermission("lindi:provinceIndex:get")
    public R<PageResp<LindiProvinceIndexVO>> getPageProvinceIndexList(LindiProvinceIndexQueryVO queryVO){
        return feignClient.getPageProvinceIndexList(queryVO);
    }

    @GetMapping("/getProvinceIndexByProvinceIndexId/{provinceIndexId}")
    @Operation(summary = "根据省级指标ID查询省级指标")
    @SaCheckPermission("lindi:provinceIndex:get")
    public R<LindiProvinceIndexVO> getProvinceIndexByProvinceIndexId(
            @PathVariable(value = "provinceIndexId")
            @NotNull(message = "省级指标ID不能为空")
            @Parameter(name = "provinceIndexId", description = "省级指标ID", required = true)
            Long provinceIndexId){
        return feignClient.getProvinceIndexByProvinceIndexId(provinceIndexId);
    }
}